package leftRightDifference;

public class Solution {
    public int[] leftRightDifference(int[] nums) {
        int n = nums.length;
        int[] ans = new int[n];
        int[] lefSum = new int[n];
        int[] rigSum = new int[n];
        for (int i = 1; i < n; i++) {
            lefSum[i] = lefSum[i-1] + nums[i-1];
            rigSum[n-i-1] = rigSum[n-i] + nums[n-i];
        }
        for (int i = 0; i < n; i++) {
            ans[i] = Math.abs(lefSum[i] - rigSum[i]);
        }
        return ans;
    }
}
